#ifndef __CSCENE__H__
#define __CSCENE__H__

#define GET_ACTOR_LIST(id)	((id >> 12) & 0xF)
#define GET_ACTOR_ID(id)	(id & 0xFFF)
	
#include <stdarg.h>

class CScene
{
protected:
	CScript** m_scripts;
	CActor*** m_actors;
	CActor** m_storeActors;
	//CActor* m_tileset;
	CActor* m_camera;
	CScript* m_script;

	// To optimize actor management
	INT32** m_actorMap;
	INT32* m_numActors;

	// Evaluation
	INT32 EvalExp(INT32* params, UINT8 start, UINT8 end, UINT8* weight = NULL);
	bool EvalCond(INT32* params, UINT8 start, UINT8 end);

	void SetActorParams(INT32 id, UINT8 numParams, INT32* params);
	bool IsValidActorID(INT8 actList, INT32 actID);

public:
	CScene();
	~CScene();

	void SetScript(UINT8 slot, CScript* script);
	void SetScript(UINT8 slot, UINT32 resID);
	void EndScript(UINT8 slot);
	bool ExecuteCommand(UINT16 cmd, INT32* params, bool isScriptCommand = false, UINT8 numParams = 0);
	bool ExecuteCommand(UINT16 cmd, UINT8 numParams, ...);

	void Update();
	void Paint();

	void RemoveActor(INT32 id);
	void RemoveActor(INT8 list, INT32 id);
	CActor* AddActor(INT32 actID, UINT8 type, UINT8 numParams);
	CActor* GetActor(INT32 id)					{return m_actors[GET_ACTOR_LIST(id)][GET_ACTOR_ID(id)];}
	CActor* GetActor(INT8 list, INT32 id)		{return m_actors[list][id];}
	CActor* GetCamera()							{return m_camera;}
	//cTileManager* GetTileManager()			{return m_tileset->m_tileManager;}
	UINT8 Pool_GetNumActors(INT8 list)			{return m_numActors[list];}
	CActor* Pool_GetActor(INT32 id)				{return m_actors[GET_ACTOR_LIST(id)][m_actorMap[GET_ACTOR_LIST(id)][GET_ACTOR_ID(id)]];}
	CActor* Pool_GetActor(INT8 list, INT32 id)	{return m_actors[list][m_actorMap[list][id]];}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
};

#endif // __CSCENE__H__